package com.vx.service.impl;

import java.util.List;
import java.util.Map;
import java.util.Random;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.vx.dao.IUserDao;
import com.vx.service.IUserService;
import com.vx.vo.RoleVO;
import com.vx.vo.UserVO;

@Service("userService")
public class UserServiceImpl implements IUserService {
	
	@Autowired
	private IUserDao userDao;

	@Override
	public UserVO findUserByName(String userCode) {
		return userDao.findUserByCode(userCode);
	}

	@Override
	public String getLeader(String userCode) {
		String[] userCodes=new String[]{"wangwei","libai","dufu","baijuyi","liqingzhao"};
		Random r=new Random();
		String leaderCode=null;
		do{
			int i=r.nextInt(userCodes.length);
			leaderCode=userCodes[i];
		}while(leaderCode.equals(userCode));
		return leaderCode;
	}

	@Override
	public List<Map<String,Object>> getRoleUser(String roleCode) {
		return userDao.getRoleUser(roleCode);
	}

	@Override
	public RoleVO getRole(String userCode) {
		return userDao.getRole(userCode);
	}

	@Override
	public RoleVO getRole(int roleId) {
		return userDao.getRole(roleId);
	}
}
